package com.haiberg.framework.services;

import java.util.List;

import org.springframework.stereotype.Service;

import com.haiberg.framework.dao.PersonDAO;
import com.haiberg.framework.om.Person;

@Service("personService")
public class PersonService {
	private PersonDAO personDAO;
	
	
	public PersonDAO getPersonDAO() {
		return personDAO;
	}

	public void setPersonDAO(PersonDAO personDAO) {
		this.personDAO = personDAO;
	}

	public int addPerson(Person dept) throws Exception {
		return personDAO.save(dept);
	}

	public void deletePerson(int id) throws Exception {
		personDAO.delete(getPersonById(id));
	}

	public Person getPersonById(int id) throws Exception {
		return personDAO.findById(id);
	}

	@SuppressWarnings("unchecked")
	public List<Person> getPersonList() throws Exception {
		return personDAO.findAll();
	}

	public void updatePerson(Person dept) throws Exception {
		personDAO.merge(dept);
	}

}
